<?php
require_once("../../Config.php");
require_once("../../Class/ClassMysql.php");
require_once("../../Class/ClassCheck.php");
require_once("../../Class/ClassResult.php");

//json头
header("Content-type: application/json");

session_start();
if(!isset($_SESSION["name"])) {
    exit(Result::jsonReturn(1, "未登录"));
}

$uid = $_SESSION["id"];
$uname = $_SESSION["name"];
$uemail = $_SESSION["email"];
$upower = $_SESSION["power"];

if((int)$upower == 0) {
    exit(Result::jsonReturn(1, "权限不足"));
}

$id = 0;
// 校验是否为空
if(Check::isEmpty($_POST["id"])) {
    exit(Result::jsonReturn(1, "未传入正确信息"));
}

// 校验是否符合格式
if(Check::isNum($_POST["id"], "int")) {
    $id = $_POST["id"];
}else {
    exit(Result::jsonReturn(1, "未传入正确信息"));
}

if((int)$id == (int)$uid) {
    exit(Result::jsonReturn(1, "不能删除自己"));
}

$db = new DB();
$sql = "DELETE FROM qilian_users WHERE id={$id}";
if($db->delete($sql)) {
    exit(Result::jsonReturn(0, "删除用户成功", array(
        "id"=>(int)$id)));
}else {
    exit(Result::jsonReturn(1, "删除用户失败"));
}

?>